package com.beauty.dressing.module.community.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.beauty.dressing.R;
import com.beauty.dressing.common.base.BaseActivity;
import com.beauty.dressing.common.bean.BaseBean;
import com.beauty.dressing.common.bean.Comment;
import com.beauty.dressing.common.bean.GroupNavigation;
import com.beauty.dressing.common.utils.ResUtil;
import com.beauty.dressing.logic.control.LBController;
import com.beauty.dressing.module.common.adapter.CommentAdapter;
import com.beauty.dressing.module.community.holder.PostsViewHolder;
import com.framework.library.haorefresh.HaoRecyclerView;
import com.framework.library.haorefresh.ProgressView;
import com.xiaolanba.commonlib.fresco.FrescoUtil;

import java.util.ArrayList;
import java.util.List;

public class PostDetailActivity extends BaseActivity {
    private HaoRecyclerView mRecyclerView;
    private CommentAdapter mAdapter;
    private PostsViewHolder mHeaderHolder;
    SwipeRefreshLayout mSwipeRefresh;
    public static void startActivity(Context context){
        Intent intent = new Intent(context,PostDetailActivity.class);
        context.startActivity(intent);
    }
    @Override
    public void setContentView() {
        setContentView(R.layout.common_haorefresh_has_title);
    }

    @Override
    public void findView() {
        findViewById(R.id.left_img_btn).setOnClickListener(this);
        mRecyclerView = (HaoRecyclerView) findViewById(R.id.hao_recycleview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.addOnScrollListener(FrescoUtil.getPauseOnScrollListener());

        mSwipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
        mSwipeRefresh.setColorSchemeResources(R.color.theme_blue, R.color.theme_blue, R.color.theme_blue);
        //设置自定义加载中和到底了效果
        ProgressView progressView = new ProgressView(context);
        progressView.setIndicatorId(ProgressView.BallPulse);
        progressView.setIndicatorColor(ResUtil.getColor(R.color.theme_blue));
        mRecyclerView.setFootLoadingView(progressView);
        TextView textView = new TextView(context);
        textView.setText("全部加载完成");
        mRecyclerView.setFootEndView(textView);
        mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                LBController.MainHandler.postDelayed(new Runnable() {
                    public void run() {
                        mSwipeRefresh.setRefreshing(false);

                    }
                }, 2000);

            }
        });
        mRecyclerView.loadMoreEnd();
    }

    @Override
    public void initData() {
        mAdapter = new CommentAdapter(context);
        mHeaderHolder = new PostsViewHolder(context,mInflater,mRecyclerView);
        mHeaderHolder.setNeedOnClick(false);
        mHeaderHolder.bindData(null,0);
        mAdapter.addHeaderView(mHeaderHolder.itemView);
        List<BaseBean> list = new ArrayList<>();
        list.add(new GroupNavigation(0,"全部评论",false,true));
        for (int i=0;i<15;i++){
            list.add(new Comment());
        }
        mAdapter.setChild(list);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.left_img_btn:
                finish();
                break;
        }
    }
}
